package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.UserHandle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    private TextView etMain;

    String prefName ="com.example.myapplication";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        saveDatawishSharedPreferences();
        etMain=(TextView)findViewById(R.id.et_main);
       Intent intent1 =getIntent();
        String username = intent1.getStringExtra("username");

        if (username!=null){
            UserInfo userInfo = new UserInfo(intent1.getStringExtra("username"),
                    intent1.getStringExtra("password"),
                    intent1.getIntExtra("age",0),
                    intent1.getBooleanExtra("gender",false));

            etMain.setText("用户名："+ userInfo.username
            +"\r\n密码："+userInfo.password+"\n年龄："+userInfo.age
                    +"\n性别："+userInfo.gender
            );
        }
        else {
            Intent intent = new Intent(this, Login.class);
            startActivity(intent);
            finish();
        }
    }


    public  void saveDatawishSharedPreferences(){
        SharedPreferences sharedPreferences =getSharedPreferences(prefName,MODE_PRIVATE);
        SharedPreferences.Editor edit=sharedPreferences.edit();
        edit.putBoolean("bool",false);
        edit.putFloat("float",(float)3.13);
        edit.putInt("int",123);
        edit.putString("username","linji");
    }

}